package cn.edu.scau.cmi.zenglinghong.client;


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import cn.edu.scau.cmi.zenglinghong.simpleFactory.domain.Beef;
import cn.edu.scau.cmi.zenglinghong.simpleFactory.domain.Chicken;
import cn.edu.scau.cmi.zenglinghong.simpleFactory.domain.Meat;
import cn.edu.scau.cmi.zenglinghong.simpleFactory.domain.Pork;

public class SimpleFactoryClient extends Application{

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		init(primaryStage);
	}

	public static void init(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Label label = new Label("请输入需要的肉类(pork,beef,chicken):");
		TextField textField = new TextField();
		Button button = new Button("确认");
		TextArea textArea = new TextArea();
		textArea.setEditable(false);
		
		VBox root = new VBox();
		root.getChildren().add(label);
		root.getChildren().add(textField);
		root.getChildren().add(button);
		root.getChildren().add(textArea);
		root.setSpacing(20);
		
		Scene scene = new Scene(root,400,300);
		primaryStage.setScene(scene);
		primaryStage.setTitle("简单工厂模式");
		primaryStage.show();
		
		button.setOnAction(Handle -> {
			Meat meat = null;
			switch (textField.getText()) {
			case "beef":
				meat = new Beef(); break;
			case "chicken":
				meat = new Chicken(); break;
			case "pork":
				meat = new Pork(); break;
			default:
				textArea.setText("There is no such meat.");
			}
			if(meat != null) {
				//meat.cook();
				textArea.setText(textField.getText()+" is delicious.");
			}
		});
		
	}
	
//	public static void main(String[] args) {
//		Scanner in = new Scanner(System.in);
//		System.out.println("请输入需要的肉类(pork,beef,chicken):");
//		String meatType = in.next();
//		in.close();
//		Meat meat = MeatFactory.getMeat(meatType);
//		if(meat != null) meat.cook();
//	}

}
